package main

import (
	"flag"
	"fmt"
	"time"
)

func Gomysql2() {
	switch *Module {
	case "hotaccount":

	case "asyncpay":
		Sync()
	default:
		fmt.Println(*Module)
	}

	testsum := GetSum()
	fmt.Println("测试中的总和：", testsum)
	Count++
}

func Gomysql(ch chan int64) {

	switch *Module {
	case "hotaccount":
		HotAccount()
	case "asyncpay":
		Asyncpay()
	default:
		fmt.Println(*Module)
	}
	Count++
	ch <- 1
}

func ParallHot() {
	t1 := time.Now()
	flag.Parse()
	//fmt.Println("Shell:", *Shellscript)
	maxs := *Thread
	fmt.Println("Threads:", maxs)
	chs := make([]chan int64, maxs)
	t2 := time.Now()
	d := t2.Sub(t1)
	for d < *Times {
		for i := 0; i < maxs; i++ {
			chs[i] = make(chan int64)
			//	go Gorun(chs[i])
			go Gomysql(chs[i])
		}
		for _, ch := range chs {
			<-ch
		}

		t2 = time.Now()
		d = t2.Sub(t1)
		if d%100 == 0 {
			Gomysql2()
		}

	}
	Gomysql2()
	t2 = time.Now()
	d = t2.Sub(t1)
	fmt.Println("Time Count:", d)
	fmt.Println("Count:", Count)
	fmt.Println("TPS:", Count/(int64(d)/1000000000))
}
